package com.stendahls.groupbot;

import com.google.wave.api.RobotMessageBundle;

import java.util.Collection;
import java.util.List;

/**
 *
 */
public class AddAllCommand extends AbstractCommand {
   
    public void perform(RobotMessageBundle robotMessageBundle) {
        StringBuffer result = new StringBuffer();

        List<String> waveParticipants = robotMessageBundle.getWavelet().getParticipants();
        Collection<String> groupParticipants = ParticipantManager.getInstance().getGroupParticipants();
        for (String groupParticipant : groupParticipants) {
            if (!waveParticipants.contains(groupParticipant)) {
                robotMessageBundle.getWavelet().addParticipant(groupParticipant);
                result.append(String.format("added %s\n", groupParticipant));
            }
        }

        if (result.length() == 0) {
            result.append("all group participants are already in wave.");
        }

        robotMessageBundle.getWavelet().appendBlip().getDocument().append(result.toString());
    }
}
